home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: very simple newbie question
- Date: 28 Feb 1996 16:04:44 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb28090444@qcd.lanl.gov>
- References: <robertk-2802960012350001@robertk.accessone.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: robertk@accessone.com's message of 28 Feb 1996 07:13:20 GMT
-
- In article <robertk-2802960012350001@robertk.accessone.com>
- robertk@accessone.com (robertk) writes:
- <snip>
- r: #include <stdio.h>
- r: main()
- r: {
- r: char s[10];
- r: scanf("%s/n",s);
- r: printf("%s",s);
- r: }
- r:
- r: when i run this and input:
- r:
- r: robert <enter> --->when i hit the enter key the cursor
- r: drops down a line and sits
- ther flashing
- r: waiting for me to enter
- another character
- r: like x before it will throw me
- back to the
- r: ide. upon returning to the
- screen i see
- r: robert
- r: x
- r: robert
- r:
- r: i thought scanf() ignored whitespace?
-
-
- First, /n is not white space, it is the character '/' followed by the
- character 'n'. When /n appears as a part of the format string for
- scanf, it tells scanf to read and discard the characters / and n if
- they follow. As the end of line is not a /, the behaviour is not
- consistent with your code. Check your code before wasting people's
- time with it.
-
- Next, whitespace is not ignored in scanf. It means read and discard
- all following whitespace. So, scanf has to continue reading till it
- finds a non-whitespace character, which it leaves unread. This
- explains the behaviour that you see.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-